package com.dys.controller;

import com.dys.listenner.MyHttpSessionListener;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author: 疾风
 * @ClassName: ThymeleafController
 * @Description: Thymeleaf控制器
 * @CreateDate: 2024/11/21
 * @Version: v1.0.0
 */
@Controller
public class ThymeleafController {

    @RequestMapping("/login")
    @ResponseBody
    public String login(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("username", "admin");
        return "login";
    }

    /**
     * 先发送login请求，然后再发送online的请求，需要注释掉servlet相关代码才生效
     * @return 在线人数统计
     */
    @RequestMapping(value = "online")
    @ResponseBody
    public String online(){
        return "当前在线人数："+ MyHttpSessionListener.online + "人";
    }
}
